<template>
    <div>
        <eagle-page-list ref="eaglePageList" @bindData="bindData" :queryParams="queryParams" :controller="controller" :conditions="conditions" :pageSize="20">
            <div slot="list">
                <div>
                    <van-row gutter="20">
                        <van-col>
                            <!-- <div class="add" @click="userChooseDialogShow1 = true">选择人员</div> -->
                            <button @click="userChooseDialogShow1 =true">选择人员</button>
                        </van-col>
                        <van-col>
                            <!-- <div class="adddept" @click="deptChooseDialogShow = true">选择部门</div> -->
                            <button @click="deptChooseDialogShow=true">选择部门</button>
                        </van-col>
                        <van-col>
                            <!-- <div class="adddept" @click="Whole = true">全员查看</div> -->
                            <button @click="Whole1">全员查看</button>
                        </van-col>
                    </van-row>
                </div>
                <van-cell class="card" v-for="(item, index) in list" :key="index">
                    <div>
                        <div>
                            <van-row gutter="20">
                                <van-col>
                                    <img class="icon" src="@/assets/Images/AppIcon/icon_list_user.png" />姓名：{{ item.UserChnName }}
                                </van-col>
                            </van-row>
                            <van-row gutter="20">
                                <van-col>
                                    <img class="icon" src="@/assets/Images/AppIcon/icon_list_user.png" />是否查看：{{  GetAssist(item.IsAssist) }}
                                </van-col>
                            </van-row>
                            <van-row gutter="20">
                                <van-col>
                                    <img class="icon" src="@/assets/Images/AppIcon/icon_list_user.png" />查看时间：{{ item.LookTime | formatDate }}
                                </van-col>
                            </van-row>
                            <van-row gutter="20">
                                <van-col>
                                    <img class="icon" src="@/assets/Images/AppIcon/icon_list_type.png" />岗位：{{ item.PostName }}
                                </van-col>
                            </van-row>
                            <van-row gutter="20">
                                <van-col>
                                    <img class="icon" src="@/assets/Images/AppIcon/icon_list_type.png" />部门：{{ item.OrgName  }}
                                </van-col>
                            </van-row>

                            <van-divider />
                            <div class="op_btn">
                                <div class="btn_item" @click="deletePlan1(item)">
                                    <img src="@/assets/Images/AppIcon/icon_list_delete.png" alt="" />
                                    <div class="mr-10">移除</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </van-cell>
            </div>
        </eagle-page-list>
        <!-- <dialog-page-list title="选择人员" confirmButton="确认" :show.sync="userChooseDialogShow1" :url="this.$constUrl.CHOOSE_USER" :isMulti="true" :params="userParams" @callback="userChooseCallback1" @initList="_initListUser">
                <van-cell v-for="(item, index) in listUser" :key="index">
                    <div class="risk_item_radio">
                        <div class="mb-5">
                            <div class="mb-10">{{ item.ChnName }}</div>
                            <div>
                                {{ item.OrgFullName
              }}<span v-if="item.OrgFullName && item.PostName"></span>{{ item.PostName }}
                            </div>
                        </div>
                        <van-checkbox :name="item.UserName"></van-checkbox>
                    </div>
                </van-cell>
            </dialog-page-list> -->
        <user-choose-dialog title="选择人员" :show.sync="userChooseDialogShow1" :isMulti="true" @callback="userChooseCallback1">
        </user-choose-dialog>
        <user-org-choose-dialog title="选择部门" :show.sync="deptChooseDialogShow" :isMulti="true" @callback="deptChooseDialogShow1">
        </user-org-choose-dialog>
    </div>

</template>
<script>
import {
    GetPageData,
    deletePlan,
    WhAccidentInitialReportSendSave,
    Whole,
} from "@/api/WhAccidentInitialReportSend";
import investigateList from "@/views/wh/AccidentInvestigate/List.vue";
import UserChooseDialog from "@/views/components/user/userChooseDialog.vue";
import UserOrgChooseDialog from "@/views/components/department/departmentChooseDialog.vue";
export default {
    components: { investigateList, UserChooseDialog, UserOrgChooseDialog },
    data() {
        return {
            value: "",
            list: [],
            controller: "/WhAccidentInitialReportSend",
            userChooseDialogShow1: false,
            myLoading: false,
            myFinished: false,
            userChooseDialogShow: false,
            deptChooseDialogShow: false,
            searchValue: "",
            conditions: [],
            dataType: "",
            queryParams: {
                dataType: "Distribute",
                keywords: "",
                AccidentNumber: "",
            },
            userParams: [
                {
                    Name: "ChnName",
                    dataType: "List",
                    accounted: true,
                    userKind: 0,
                },
            ],
            listUser: [],
        };
    },
    created() {
        this.queryParams.AccidentNumber = this.$route.query.AccidentNumber;
        // this.dataType = this.$route.query.dataType;
        // this.conditions.push({
        //     Name: "AccidentNumber",
        //     Value: AccidentNumber,
        //     Operator: "like",
        //     DataType: "String",
        // });
    },
    mounted() {
        //this.queryPage();
    },
    methods: {
        clearSearch() {
            this.value = "";
            //this.getList();
        },
        Whole1() {
            const that = this;

            that.$dialog
                .confirm({
                    title: "询问",
                    message: "您确定将本条调查报告发布全员吗？",
                })
                .then(() => {
                    Whole({
                        AccidentNumber: this.$route.query.AccidentNumber,
                    }).then((res) => {
                        this.$toast.success("发布成功");
                        this.bindData();
                    });
                })
                .catch(() => {
                    // on cancel
                });
        },
        deletePlan1(item) {
            //调查报告删除
            const that = this;

            that.$dialog
                .confirm({
                    title: "询问",
                    message: "您确定要移除该人员吗？",
                })
                .then(() => {
                    deletePlan({ id: item.ID }).then((res) => {
                        this.$toast.success("移除成功！");
                        this.bindData();
                        //that.queryPage();
                    });
                })
                .catch(() => {
                    // on cancel
                });
        },
        _initListUser(list) {
            this.listUser = list;
        },
        userChooseCallback1(data) {
            this.loading = true;
            var form1 = {};
            var UserNames = [];
            data.map((item) => {
                UserNames.push(item.code);
            });
            form1.IsAssist = null;
            form1.UserNames = UserNames;
            form1.PublishType = "C";
            form1.AccidentNumber = this.$route.query.AccidentNumber;
            WhAccidentInitialReportSendSave(form1)
                .then((res) => {
                    this.loading = false;
                    this.userChooseDialogShow1 = false;
                    this.bindData();
                    //this.queryPage();
                })
                .catch((err) => {
                    console.log("err", err);
                });
        },
        // search(conditions) {
        //     this.conditions = [];
        //     this.queryPage();
        // },
        // queryPage() {
        //     let _this = this;
        //     _this.$refs.eaglePageList.search({
        //         conditions: _this.conditions,
        //         params: { keywords: this.searchValue },
        //     });
        // },
        bindData(data) {
            this.list = [];
            if (data) {
                this.list = data;
            }
        },
        deptChooseDialogShow1(data) {
            this.loading = true;
            var form1 = {};
            var UserNames = [];
            data.list.map((item) => {
                UserNames.push(item.OrgCode);
            });
            form1.UserNames = UserNames;
            form1.AccidentNumber = this.$route.query.AccidentNumber;
            form1.PublishType = "B";
            WhAccidentInitialReportSendSave(form1)
                .then((res) => {
                    this.loading = false;
                    this.bindData();
                    //this.queryPage();
                })
                .catch((err) => {
                    console.log("err", err);
                });
        },
        GetAssist(val) {
            if (val == "1") {
                return "是";
            } else {
                return "否";
            }
        },
        // getMyList() {
        //     //调查报告显示
        //     this.myLoading = true;
        //     GetPageData(this.filter).then((res) => {
        //         this.myLoading = false;
        //         this.list = res.data.Data;
        //         this.filter.page = res.data.PageIndex;
        //     });
        // },
        GetPublishType(value) {
            if (value == "B") {
                return "部门";
            } else {
                return "员工";
            }
        },
        myOnLoad() {
            this.myLoading = true;
            this.filter.page;
            list(this.filter).then((res) => {
                this.myLoading = false;
                this.filter.page = res.data.PageIndex;
                this.myList = this.myList.concat(res.data.Data);
                if (!res.data.HasNextPage) {
                    this.myFinished = true;
                }
            });
        },
        onLoad() {
            this.loading = true;
            ++this.filter.page;
        },
        tabChange(val) {
            this.tabName = val;
        },
    },
};
</script>
<style lang="less" scoped>
.register-form {
}
.phone {
    position: relative;
    .code {
        position: absolute;
        right: 20px;
        top: 20px;
        font-size: 12px;
    }
}
.register-info {
    background-color: #e8f1f8;
    padding-bottom: 20px;
}
.img-box {
    height: 50px;
    width: 50px;
    padding: 10px;
    position: absolute;
    left: 50%;
    top: 60px;
    background-color: #fff;
    border-radius: 50%;
    overflow: hidden;
}
.popup-title {
    line-height: 35px;
    padding: 10px;
    font-size: 15px;
    padding-left: 20px;
}

.op_btn {
    display: flex;
    justify-content: flex-end;
    .btn_item {
        display: flex;
        align-items: center;
        img {
            height: 15px;
            width: 15px;
            margin-right: 5px;
        }
    }
}
</style>